import { zbjAxios } from "src/boot/axios";
import { cookiesToString } from "./utils";

// 获取报价模板
export function fetchMarkBookTepList(categoryId, cookie) {
  return zbjAxios.get(
    "https://task.zbj.com/speed/api/demandInfoService/getMarkBookTepList",
    { categoryId },
    cookiesToString(cookie)
  );
}

// 获取需求详情
export function fetchDemandDetailInfo(params, cookie) {
  const def = {
    types: [1, 2, 3, 4, 5, 6, 7],
  };

  return zbjAxios.get(
    "https://task.zbj.com/speed/api/demandInfoService/getDemandDetailInfo",
    { ...def, ...params },
    cookiesToString(cookie)
  );
}

// 获取投标消耗详情
export function fetchConsumeDetail(demandId, cookie) {
  return zbjAxios.get(
    "https://task.zbj.com/speed/api/ftDemandChanceCoinService/getConsumeDetail",
    { demandId },
    cookiesToString(cookie)
  );
}

// 投标
export function addMarkBook(body, cookie) {
  return zbjAxios.post(
    "https://task.zbj.com/speed/api/demandInfoService/addMarkBook",
    body,
    cookiesToString(cookie)
  );
}

export function fetchOutSourceList(params, cookie) {
  return zbjAxios.post(
    "https://jdyboss.zbj.com/api/osg_hall/getOutSourceList",
    params,
    cookiesToString(cookie)
  );
}

// 商机列表
export function fetchChance(body, cookie) {
  const def = {
    assignStatus: 1,
    chanceStage: "",
    followResult: "",
    followerDeptList: [],
    followerId: "",
    followerList: [],
    pageNum: 1,
    pageSize: 10,
    type: 0,
  };
  return zbjAxios.post(
    "https://jdyboss.zbj.com/api/chance/pageChance",
    { ...def, ...body },
    cookiesToString(cookie)
  );
}

export function fetchChanceTypeCount(cookie) {
  return zbjAxios.get(
    "https://jdyboss.zbj.com/api/chance/getChanceTypeCount",
    null,
    cookiesToString(cookie)
  );
}

export function fetchStageList(cookie) {
  return zbjAxios.get(
    "https://jdyboss.zbj.com/api/chance/getStageList",
    null,
    cookiesToString(cookie)
  );
}

export function fetchCategoryTree(cookie) {
  return zbjAxios.get(
    "https://jdyboss.zbj.com/api/categoryManage/getCategoryTree",
    null,
    cookiesToString(cookie)
  );
}

export function getAxnNew(body, cookie) {
  const def = {
    source: "11",
    refer: "https://jdyboss.zbj.com/chance/chance_detail",
  };
  return zbjAxios.post(
    "https://tongxin.zbj.com/phone/getAxnNew",
    { ...def, ...body },
    cookiesToString(cookie)
  );
}

export function fetchOrderCustomerInfo(customerId, cookie) {
  return zbjAxios.get(
    "https://jdyboss.zbj.com/api/order/getOrderCustomerInfo",
    { customerId },
    cookiesToString(cookie)
  );
}

/**
 *
 * @param {{imKey:String,chanceId:Number}} params
 * @param {String|{userid:string}} cookie
 * @returns
 */
export function fetchTargetIMInfo(params, cookie) {
  const e = {
    key: params.imKey,
    fromPlatform: 1,
    welcome: "你好",
    clientType: "web",
    platform: 446,
    scene: 5,
    subScene: 137,
    dataId: params.chanceId,
  };

  const body = {
    key: e.key,
    fromPlatform: e.fromPlatform,
    toPlatform: 1 === e.fromPlatform ? 0 : 1,
    orgId: 0,
    welcome: e.welcome || "",
    clientType: e.clientType,
    unionJson: {},
    sessionDTO: {
      scene: e.scene,
      subScene: e.subScene,
      dataId: e.dataId,
      // data: e.data ? JSON.stringify(e.data || {}) : "",
      random: +new Date(),
    },
  };

  return zbjAxios.post(
    "https://supeicommunicate.zbj.com/api/fastim/getTargetIMInfo",
    body,
    cookiesToString(cookie)
  );
}
